package com.hzy.login;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentTransaction;
import android.widget.TextView;

import com.hzy.text.R;
import com.sam.widget.LoginNavBar;

/**
 * Created by Administrator on 2016/6/23 0023.
 */
public class MainFragmentActivity extends FragmentActivity {
    LoginNavBar loginNavBar;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main_fragment);
        findView();
        initView();
    }

    private void findView() {
        loginNavBar = (LoginNavBar) findViewById(R.id.login_nav_bar);

    }

    private void initView(){
        showFragment(LoginFragment.getInstance());

        loginNavBar.setOnLoginNavChangedListener(onLoginNavChangedListener);
    }

    private void showFragment(Fragment fragment){
        FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
        fragmentTransaction.replace(R.id.fragment_content,fragment);
        fragmentTransaction.commit();
    }


    private LoginNavBar.OnLoginNavChangedListener onLoginNavChangedListener= new LoginNavBar.OnLoginNavChangedListener(){
        private static final float UNCHECKED_ALPHA = 0.5f;
        private static final float CHECKED_ALPHA = 1.0f;
        @Override
        public void onLoginNavChanged(TextView[] items, TextView item, int position) {
            for(int i = 0; i < 2; i++) items[i].setAlpha(UNCHECKED_ALPHA);
            switch (position){
                case 0:showFragment(LoginFragment.getInstance());
                    item.setAlpha(CHECKED_ALPHA);
                    break;
                case 1:showFragment(PhoneNumLoginFragment.getInstance());
                    item.setAlpha(CHECKED_ALPHA);
                    break;
            }
        }
    };
}
